# -*- coding: utf-8 -*-
"""
描述器相关的魔术方法
"""


class D:
    def __init__(self):
        print(f'__init__ {self}')
        self.value = 0

    def __get__(self, instance, owner):
        print(f'__get__ {self} {instance} {owner}')
        return self.value

    def __set__(self, instance, value):
        print(f'__set__ {self} {instance} {value}')
        self.value = value

    def __delete__(self, instance):
        print(f'__delete__ {self} {instance}')
        del self.value


class A:
    __slots__ = ['a']  # 实例属性白名单，　该类的实例中，只能有哪些属性


    x = D()  # 类属性，所有实例共享属性值


if __name__ == '__main__':
    a = A()
    print(a.x)
    print(A.x)
    print(A.__dict__['x'])
    print(A.__dict__['x'].__get__(a, A))

    a.x = 1
    print(a.x)
    b = A()
    print(b.x)
    del b.x

    print(A.__dict__['x'])
    # print(A.x)

    a.name = 'vincent'
